<template>
  <!-- 分页 -->
  <div class="pagination-container">
    <a-pagination
      show-quick-jumper
      :current="currentPage"
      :page-size.sync="pageSize"
      :pageSizeOptions="pageSizes"
      :total="total"
      :showSizeChanger="true"
      @change="onChange"
      @showSizeChange="onShowSizeChange"
    />
  </div>
</template>

<script>

export default {
  name: 'Pagination',
  props:{
    total: {
      required: true,
      // default: 1,
      type: Number
    },
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 20
    },
    pageSizes: {
      type: Array,
      default() {
        return ['10','20','30','50']
      }
    },
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      // set(val) {
      //   console.info(val,'update:page')
      //   this.$emit('update:page', val)
      // }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods:{
    onShowSizeChange(val){
      this.$emit('pagination', { page: this.currentPage, limit: val })
    },
    onChange(val) {
      this.$emit('update:page', val)
      this.$emit('pagination', { page: val, limit: this.pageSize })
    },
  }
}
</script>

<style lang="less" scoped>
.pagination-container {
  background: #fff;
  padding: 32px 16px;
}
.pagination-container.hidden {
  display: none;
}
</style>